package net.xiduth.game;

import java.util.TimerTask;

import net.xiduth.cores.CoresManager;
import net.xiduth.game.player.Player;
import net.xiduth.utils.AutoBackup;
import net.xiduth.utils.Logger;
import net.xiduth.utils.SerializableFilesManager;

/**
 * 
 * @author Jae
 *
 */

public class BackupSystem {

	private static AutoBackup backup;
	
	static final void systemBackupTask() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					for (Player p : World.getPlayers()) {
						p.getBank().addItem(10834, 1, true);
						p.getDialogueManager().startDialogue("SimpleMessage", "A reward has been added a reward to your bank.");
						SerializableFilesManager.systemBackup(p);
					}
					backup = new AutoBackup();
					/**
					 * Moved the messages out of the for loop as players complained that it spammed the chat box when it saved a player.
					 * Kova (Alex) :)
					 */
					World.sendWorldMessage(
							"<img=7><col=FF0000>News: Account backup system completed.. Enjoy your reward in your bank!",
							false);
					//Logger.log("System", "Hourly system backup complete.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
		}, 0, 14400000);
	}

}
